﻿package net.sealuitk 
{
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	/**
	 * ...
	 * @author mkn
	 */
	public class Gadget extends Sprite
	{
		protected var parentContainer:Container;
		
		public var size:Point;
		public var sizeSet:Boolean = false;
		
		protected var padding:Rectangle = new Rectangle(0, 0, 0, 0);
		
		private var _isFloating:Boolean = false;
		
		// ========= Constructor ========
		
		public function Gadget(Name:String) {
			name = Name;
			size = new Point(0, 0);
		}
		
		// ========= Inits ========
		
		public function setSize(Width:Number, Height:Number, SizeSet:Boolean = true):void {
			sizeSet = SizeSet;
			size.x = Width;
			size.y = Height;
			
			if (mask == null) {
				mask = Util.buildMask(0, 0, size.x, size.y);
				this.addChild(mask);
			}
			else {
				mask.width = Width;
				mask.height = Height;
			}
		}
		
		public function setPadding(top:int, bottom:int, left:int, right:int):void {
			padding.top = top;
			padding.bottom = bottom;
			padding.left = left;
			padding.right = right;
			x = padding.left;
			y = padding.top;
		}
		
		public function makeChild(ofContainer:Container, IsFloating:Boolean = false):void {
			parentContainer = ofContainer;
			_isFloating = IsFloating;
			
			if (mask != null) parentContainer.addChild(mask);
		}
		
		public function update():void {
			updateParentContainer();
		}
		
		public function updateParentContainer():void {
			if (parentContainer != null) parentContainer.update();
		}
		
		public function updateContent():void {
		}
		
		// ========= Getters & Setters ========
		
		override public function set x(value:Number):void {
			super.x = value;
			if (mask != null) {
				mask.x = x;
			}
			
		}
		
		override public function set y(value:Number):void {
			super.y = value;
			if (mask != null) mask.y = y;
		}
		
		override public function get width():Number {
			return size.x;
		}
		
		override public function get height():Number { 
			return size.y; 
		}
		
		override public function set width(value:Number):void {
			setSize(value, height);
		}
		
		override public function set height(value:Number):void {
			setSize(width, value);
		}
		
		public function get isFloating():Boolean { 
			return _isFloating; }
		
	}
}